# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]

head(newdata)

# ------------------------------------------
# 任务回顾一
# ------------------------------------------

cdata1 <- newdata[1:5, 1:3]
cdata2 <- newdata[1:5, 4:7]

cdata3 <- newdata[1:5, c("EmployeeNumber", "Age", "EnvironmentSatisfaction",
                      "JobSatisfaction", "MonthlyIncome", "RelationshipSatisfaction")]
cdata3 <- cdata3[order(-cdata3$EmployeeNumber),]

cdata1
cdata2
cdata3

# ------------------------------------------
# 任务回顾二
# ------------------------------------------

rdata1 <- newdata[1:5,]
rdata2 <- newdata[6:10,]

rdata1
rdata2

# ------------------------------------------
# 任务一
# ------------------------------------------

total1 <- cbind(cdata1, cdata2)
total1

total2 <- merge(cdata1, cdata3, by = c("EmployeeNumber", "Age"))
total2

# ------------------------------------------
# 任务二
# ------------------------------------------

total3 <- rbind(rdata1, rdata2)
total3

total4 <- rbind(cdata1, rdata2)
total4

cdata1$EnvironmentSatisfaction <- NA
cdata1$JobSatisfaction <- NA
cdata1$MonthlyIncome <- NA
cdata1$RelationshipSatisfaction <- NA